package org.ws.task.netty;

import io.netty.channel.Channel;
import org.ws.task.netty.handler.ActionHandlerRegistry;
import org.ws.task.netty.manager.ChannelConnectManager;
import org.ws.task.model.protocol.base.RequestMessage;
import org.ws.task.netty.support.ResponseFuture;
import org.ws.task.model.protocol.base.ResponseMessage;

import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;

public interface NettyServer extends NettyService{

    ChannelConnectManager getChannelConnectManager();

    /**
     * action处理器
     * @param actionHandlerRegistry
     * @param executor
     */
    void actionHandlerRegistry(ActionHandlerRegistry actionHandlerRegistry, ExecutorService executor);

    /**
     * 同步
     */
    ResponseMessage sync(Channel channel, RequestMessage request, long timeout)throws Exception;

    /**
     * 异步
     * @param channel
     * @param request
     * @param timeout
     * @param callback
     * @throws Exception
     */
    void async(Channel channel, RequestMessage request, long timeout, Consumer<ResponseFuture> callback)throws Exception;

    /**
     * 单向：无需响应
     * @param channel
     * @param request
     * @param timeout
     * @throws Exception
     */
    void oneWay(Channel channel, RequestMessage request, long timeout)throws Exception;
}
